﻿

var xHRObject = false;

if (window.ActiveXObject)
{
xHRObject = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xHRObject = new XMLHttpRequest();
}

function getData()
{
    if ((xHRObject.readyState == 4) &&(xHRObject.status == 200))
    {
        var serverResponse = xHRObject.responseXML;
        var header = serverResponse.getElementsByTagName("book");
        var spantag = document.getElementById("cart");
        spantag.innerHTML = "";
        for (i=0; i<header.length; i++)
        {
           
        if (window.ActiveXObject)
        {
             spantag.innerHTML += " " +header[0].firstChild.text;
             spantag.innerHTML += " " + header[0].lastChild.text + " " + "<a href='javascript:AddRemoveItem(\"Remove\");'>Remove Item</a>";
        }
        else
        {
             spantag.innerHTML += " " +header[0].firstChild.textContent;
             spantag.innerHTML += " " + header[0].lastChild.textContent + " " + "<a href='javascript:AddRemoveItem(\"Remove\");'>Remove Item</a>";
        }
       }
    }
}

function getBody()
{
     var argument = "book=";
     argument += encodeURI(book.innerHTML); 
     argument += "&ISBN=";
     argument += encodeURI(ISBN.innerHTML); 
     argument += "&authors=";
     argument += encodeURI(authors.innerHTML); 
     argument += "&price=";
     argument += encodeURI(price.innerHTML); 
     return argument;
}

function AddRemoveItem(action)
{
          var book  = document.getElementById("book").innerHTML;
          var num = (Math.round((Math.random()*999999)+1));
           var newform = document.forms[0];
var bodyofform = getBody(newform); 
           
          if(action=="Add")
          {
          xHRObject.open("POST", newform.action, true);
          xHRObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          xHRObject.onreadystatechange = getData;
xHRObject.send(bodyofform); 
            
          }
          else
          {
           xHRObject.open("POST", newform.action, true);
xHRObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xHRObject.onreadystatechange = getData;
xHRObject.send(bodyofform); 
          }
         
}




